/**
 * Created by cc
 * Description:
 * User: CZH
 * Date: 2022-09-10
 * Time: 16:09
 */
public class Test01 {


    public static int jumpFloor(int n){
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }
        return jumpFloor(n - 1) + jumpFloor(n - 2);
    }
    public static void main(String[] args) {
        int num = 5;
        System.out.println(jumpFloor(num));
    }


    //汉诺塔问题
    public static void move(char pos1, char pos3){
        System.out.println(pos1 + " -> " + pos3);
    }

    /**
     *
     * @param n
     * @param pos1
     * @param pos2
     * @param pos3
     */
    public static void hanoiTower(int n, char pos1, char pos2, char pos3){
        if (n == 1) {
            move(pos1, pos3);
        }else {
            hanoiTower(n-1, pos1, pos3, pos2);
            move(pos1, pos3);
            hanoiTower(n-1, pos2, pos1, pos3);
        }
    }
    public static void main7(String[] args) {
        hanoiTower(3,'A','B','C');
    }




    public static int fib1(int n){
        if (n < 3) {
            return 1;
        }
        int tmp = 0;
        int last1 = 1;
        int last2 = 1;
        for (int i = 3; i <= n; i++){
            tmp = last1 + last2;
            last1 = last2;
            last2 = tmp;
        }
        return tmp;
    }
    public static void main6(String[] args) {
        int num = 7;
        System.out.println(fib1(num));
    }



    //斐波那契数列的第 N 项
    //1 1 2 3 5 8 13
    public static int count = 0;
    public static int fib(int n){
        if (n < 3) {
            return 1;
        }
        if (n == 3) {
            count++;
        }
        return fib(n - 1) + fib(n - 2);
    }
    public static void main5(String[] args) {
        int num = 40;
        System.out.println(fib(num));
        System.out.println(count);
    }

    //写一个递归方法，输入一个非负整数，返回组成它的数字之和.
    // 例如，输入 1729, 则应该返回1+7+2+9，它的和是19
    public static int print1(int n){
        if (n < 10) {
            return n;
        }
        return (n % 10) + print1(n / 10);
    }
    public static void main4(String[] args) {
        int num = 1729;
        System.out.println(print1(num));
    }

    //递归求 1 + 2 + 3 + ... + 10
    public static int sumNum(int n){
        if (n == 1) {
            return 1;
        }
        return n + sumNum(n - 1);
    }
    public static void main3(String[] args) {
        int n = 10;
        System.out.println(sumNum(n));
    }


//    /1234 打印出 1 2 3 4
    public static void print(int n){
        if (n > 9) {
            print(n / 10);
        }
        System.out.println(n % 10);
    }
    public static void main2(String[] args) {
        int num = 1234;
        print(num);
    }

//    public static int fac(int n){
//        if (n == 1) {
//            return 1;
//        }
//        return n * fac(n - 1);
//    }
//
//    public static void main(String[] args) {
//        int num = 3;
//        int ret = fac(num);
//        System.out.println(ret);
//    }



//    public static double add(double a, double b, double c){
//        return a + b + c;
//    }
//    public static double add(double a, double b){
//        return a + b;
//    }
//    public static int add(int a, int b){
//        return a + b;
//    }
//
//    public static void main(String[] args) {
//        int a1 = 10;
//        int b1 = 20;
//        System.out.println(add(a1,b1));
//        double a2 = 1.0;
//        double b2 = 2.0;
//        System.out.println(add(a2,b2));
//        double c2 = 3.0;
//        System.out.println(add(a2,b2,c2));
//    }



//    public static void print(int x, int y){
//        System.out.println(x);
//        System.out.println(y);
//    }
//
//    public static void main(String[] args) {
//        int a = 10;
//        int b = 20;
//        print(a, b);
//    }



//    public static void swap(int[] arr){
//        int tmp = arr[0];
//        arr[0] = arr[1];
//        arr[1] = tmp;
//    }
//
//    public static void main(String[] args) {
//        int[] arr = {10,20};
//        swap(arr);
//        System.out.println(arr[0]);
//        System.out.println(arr[1]);
//    }



//    public static int add(int x, int y){
//        return x + y;
//    }
//
//    public static void main(String[] args) {
//        int a = 10;
//        int b = 20;
//        int ret = add(a,b);
//        System.out.println(ret);
//    }
}
